package cn.thoughtworks.school.services;

import cn.thoughtworks.school.entities.UserRole;
import cn.thoughtworks.school.entities.commands.CreateUserRoleCommand;
import cn.thoughtworks.school.feign.CourseCenterFeign;
import cn.thoughtworks.school.feign.UserCenterFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserCenterService {
  @Autowired
  private UserCenterFeign userCenterFeign;
  @Autowired
  private CourseCenterFeign courseCenterFeign;

  public Map getUserInfo(Long userId) {
    return userCenterFeign.getUserById(userId);
  }

  public List<Map> getUserByUserNameOrEmail(String userNameOrEmail) {
    return userCenterFeign.getUserByUserNameOrEmail(userNameOrEmail);
  }

  public void updateUserRole(CreateUserRoleCommand createUserRoleCommand) {
    Map userRole = new HashMap();
    userRole.put("userId", createUserRoleCommand.getUserId());
    userRole.put("roleNumber", createUserRoleCommand.getRoleNumber());
    userRole.put("organizationId", createUserRoleCommand.getOrganizationId());
    userRole.put("type", createUserRoleCommand.getType());

    courseCenterFeign.updateUserRole(createUserRoleCommand.getUserId(), userRole);
  }

  public List<UserRole> findAdminsRoleByOrganizationId(Long organizationId) {
    return userCenterFeign.getAdminsRoleByOrganizationId(organizationId);
  }
}
